home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / DOS.SWG / 0012_Dealing with File Share.pas < prev    next >
Pascal/Delphi Source File  |  1993-06-22  |  4KB  |  115 lines

  1. ===========================================================================
  2.  BBS: Canada Remote Systems
  3. Date: 06-16-93 (16:14)             Number: 26531
  4. From: LARS HELLSTEN                Refer#: NONE
  5.   To: RITO SALOMONE                 Recvd: NO  
  6. Subj: Re: Novell/File Locking/S      Conf: (1221) F-PASCAL
  7. ---------------------------------------------------------------------------
  8. RS> Does anyone have any samples of network file sharing/access code for Turbo
  9. RS> Pascal/Borland Pascal 6-7.
  10.  
  11.    Here's some source that I use.  I haven't had a chance to test it out
  12. as much as I'd like to, but so far, it appears to work quite nicely:
  13.  
  14. --- 8< --------------------------------------------------------------------
  15. Unit Share;
  16.  
  17. INTERFACE
  18.  
  19. Uses DOS;
  20.  
  21. Var
  22.    ShareInstalled : Boolean;
  23.  
  24. Function LockRec(Var Untyped; pos, size : LongInt) : Boolean;
  25. Function UnLockRec(Var Untyped; pos, size : LongInt) : Boolean;
  26. Procedure FMode(Mode : Byte);
  27. Function Share : Boolean;
  28.  
  29. IMPLEMENTATION
  30.  
  31. Function LockRec(Var Untyped; pos, size : LongInt) : Boolean;
  32.  
  33. Var
  34.    Regs : Registers;
  35.    f : File absolute Untyped;
  36.  
  37. Begin
  38.    pos := pos * FileRec(f).RecSize;
  39.    size := size * FileRec(f).RecSize;
  40.    Regs.AH := $5C;
  41.    Regs.AL := $00;
  42.    Regs.BX := FileRec(f).Handle;
  43.    Regs.CX := Hi(pos);
  44.    Regs.DX := Lo(pos);
  45.    Regs.SI := Hi(size);
  46.    Regs.DI := Lo(size);
  47.    Intr($21,Regs);
  48.    LockRec := (Regs.Flags AND FCarry) = 0;
  49. End; { LockRec }
  50.  
  51. Function UnLockRec(Var Untyped; pos, size : LongInt) : Boolean;
  52.  
  53. Var
  54.    Regs : Registers;
  55.    f : File absolute Untyped;
  56.  
  57. Begin
  58.    pos := pos * FileRec(f).RecSize;
  59.    size := size * FileRec(f).RecSize;
  60.    Regs.AH := $5C;
  61.    Regs.AL := $01;
  62.    Regs.BX := FileRec(f).Handle;
  63.    Regs.CX := Hi(pos);
  64.    Regs.DX := Lo(pos);
  65.    Regs.SI := Hi(size);
  66.    Regs.DI := Lo(size);
  67.    Intr($21,Regs);
  68.    UnlockRec := (Regs.Flags AND FCarry) = 0;
  69. End; { UnLockRec }
  70.  
  71. Procedure FMode(Mode : Byte);
  72.  
  73. Begin
  74.    If ShareInstalled then
  75.       If (mode in [0..2,23..24,48..50,64..66]) then
  76.          FileMode := Mode;
  77. End;
  78.  
  79. function Share : boolean;
  80. var regs : registers;
  81. begin
  82.     with regs do
  83.     begin
  84.         AH := 16;
  85.         AL := 0;
  86.         Intr($2f, regs);
  87.         Share := AL = 255;
  88.     end;
  89. end; { IsShare }
  90.  
  91. Begin
  92.    ShareInstalled := Share;
  93. End. { MyShare }
  94. --- 8< ---------------------------------------------------------------------
  95.  
  96.    By the way, the unit name should be "MyShare", there's duplicate
  97. identifiers in there by accident.  All you do, is call the lock/unlock
  98. routines, passing the file variable, the record number, and the number of
  99. records (you'll see it determines the size itself, using the FileRec.RecSize
  100. variable).  The FMode procedure doesn't do much, I just use it instead of
  101. constantly putting "If ShareInstalled then FileMode :=..." inside the
  102. program(s).  You should call this to set the FileMode variable to a sharing
  103. method, before you reset the file.  Here's a table of values you can pass:
  104.  
  105.                                          Sharing Method
  106. Access Method   Compatibility  Deny Write  Deny Read  Deny None
  107. -------------------------------------------------------------------
  108. Read Only             0            32         48         64
  109. Write Only            1            33         49         65
  110. Read/Write            2            34         50         66
  111. -------------------------------------------------------------------
  112.  
  113. --- GEcho 1.00
  114.  * Origin: Access-PC BBS ■ Scarborough, ON ■ (416)491-9249 (1:250/320)
  115.